define(function(require, exports){
	var pubjs  = require('pubjs');
	var util   = require('util');
	var view   = require('@base/view');
	var $      = require('jquery');
	var popwin = require('@base/dialog').base;
	var dspUtil = require('dspUtil');
	var _convertMapToItems = dspUtil._convertMapToItems;
	var selectOnTab = require('modules/selectOnTab');

	// 出价方式候选项配置
	var CHARGE_TYPE_OPTS = [
		{value: 0, label: LANG("竞价CPM"), access: 'campaign.cpm_bid'}
		,{value: 1, label: LANG("CPA优化"), access: 'campaign.cpa_opt'}
		,{value: 2, label: LANG("CPC优化"), access: 'campaign.cpc_opt'}
		,{value: 3, label: LANG("固定CPC"), access: 'campaign.cpc_fix'}
		,{value: 4, label: LANG("固定CPM"), access: 'campaign.cpm_fix'}
	];

	var CHARGE_TEXT = {
		1: LANG('优化CPA')
		,2: LANG('优化CPC')
		,3: LANG('结算CPC')
		,4: LANG('结算CPM')
	};

	// raido值定义
	var RAIDO_VALUE_DEFINE = pubjs.config('RAIDO_VALUE_DEFINE');
	var rvd = RAIDO_VALUE_DEFINE;


	// 选择关系包含|排除组件
	var Relation = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				vModel: {
					'relation': '1'
				}
			});
			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var el = self.getDOM();

			$([
				'<div class="M-formConGroup">',
					'<label class="group-label">'+LANG('选择关系：')+'</label>',
					'<div class="group-content">',
						'<div class="M-formSectionItem">',
							'<label class="mr10">',
								'<input type="radio" v-model="relation" value="1">',
								'<span>'+LANG('包含')+'</span>',
							'</label>',
							'<label>',
								'<input type="radio" v-model="relation" value="2">',
								'<span>'+LANG('排除')+'</span>',
							'</label>',
						'</div>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);

			self.vm.mount();

			el.find('input').css('margin-right', 4);
		},
		getValue: function(){
			return +this.vm.$.relation;
		},
		setValue: function(value){
			this.vm.$.relation = value;
			return this;
		},
		reset: function(){
			this.vm.reset();
			return this;
		}
	});
	exports.relation = Relation;


	/*通用条件*/
	// 渠道
	var Channel = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'class': 'P-campaignOrientMediaChannel',
				vModel: {
					'channels': pubjs.config('exchange'),
					'selects': []
				}
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 300);

			$([
				'<div class="M-formConGroup">',
					'<div class="">' + LANG('广告渠道：') + '</div>',
					'<div class="con mt10">',
						'<div class="content" v-for="item in channels">',
							'<label v-bind:data-id="item.id">',
								'{{item.name}}',
							'</label>',
						'</div>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);

			self.uiProxy(el, '.content label', 'click', 'eventClickChannel');

			self.vm.mount();

			self.buildFromTemplate({

			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,eventClickChannel: function(evt, elm){
			var id = $(elm).attr('data-id');
			$(elm).toggleClass('select');
		}
		,setValue: function(data){
			var el = this.getDOM();

			this.$data = data;
			if(data){

				if(this.get('relation')){
					this.$.relation.setValue(data.Relation);
				}
				util.each(data.Data.AdxIds, function(item){
					if(item){
						el.find('label[data-id="'+item+'"]').addClass('select');
					}
				});
			}
			return this;
		}
		,getValue: function(){
			var el = this.getDOM();

			var sels = el.find('label.select');
			var selects = [];
			var names = [];
			$.each(sels, function(idx, item){
				var id = $(item).attr('data-id');
				var name = $(item).text();
				if(id){
					selects.push(id);
					names.push(name);
				}
			});

			var data = {
				'Data': {
					'AdxIds': selects,
					// 'Quality': 2,
					'AdCategory': [],
					'AdSensitive': []
				},
				'Relation': 1, // 默认是1，包含关系
				'Desc': '[' +names.join('、') + ']'
			}

			return data;
		}
		,reset: function(){
			this.vm.reset();
			this.$data = null;
			return this;
		}
		,validate: function(data){
			if(data.Data && !data.Data.AdxIds.length){
				pubjs.alert(LANG('至少需选择一个渠道'));
				return false;
			}
			return true;
		}
	});
	exports.channel = Channel;

	// 交易类型
	var BidType = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 300);

			$([
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('交易类型：') + '</label>',
					'<div class="group-content" pub-name="tradeMod" pub-mod="@base/common/input.radioGroup"/>',
				'</div>'
			].join('')).appendTo(el);

			var tradeTypeData = [
				{text: LANG("公开竞价"), value: 0},
				{text: LANG("私下竞价"), value: 2},
				{text: LANG("首选交易"), value: 1},
				{text: LANG("PDB"), value: 3}
			];

			self.buildFromTemplate({
				tradeMod: {
					'data': tradeTypeData,
					'value': 0
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,setValue: function(data){
			this.$data = data;
			if(data && this.get('tradeMod')){
				this.$.tradeMod.setValue(data.Data);
			}
			return this;
		}
		,getValue: function(){
			var tradeMod = this.$.tradeMod;
			var data = {
				'Data': tradeMod.getValue(),
				'Relation': 1, // 默认是1，包含关系
				'Desc': tradeMod.getFullValue().text
			}

			return data;
		}
		,reset: function(){
			this.$.tradeMod.setValue(0);
			this.$data = null;
			return this;
		}
	});
	exports.bidType = BidType;

	// RTB广告位
	var RTBSpot = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				vModel: {
					'value': ''
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();

			$([
				'<textarea v-model="value" class="ml20" rows="15" cols="80" placeholder="'+ LANG('请输入RTB广告位ID，多个ID请用回车换行隔开') + '"/>'
			].join('')).appendTo(el);

			self.vm.mount();

			self.buildFromTemplate();
		}
		,getValue: function(){
			var vm = this.vm.$;
			var values = [];
			var value = vm.value.split('\n');
			value.forEach(function(item){
				var trimItem = util.trim(item);
				if (trimItem) {
					values.push(trimItem);
				}
			});
			var data = {
				'Data': values,
				'Relation': 1,
				'Desc': values.join('、')
			};

			return data;
		}
		,setValue: function(data){
			var vm = this.vm.$;
			vm.value = data.Data.join('\n');
			return this;
		}
		,reset: function(){
			this.vm.reset();
			return this;
		}
	});
	exports.rtbSpot = RTBSpot;

	// 订单广告位
	var DealSpot = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				vModel: {
					// 是否勾选了显示已选的checkbox
					'showSelected': false,
					'clickShowSelected': this.eventShowSelected
				}
			});

			// 内部变量，用于获取选择订单广告位列表所有已选订单广告位对应的data
			this.$gridChooseData = {
				'currentData': [],
				'chooseData': [],
				'modChooseData': function(data){
					var result = [];
					var param = data.param;

					// 所有页面已选订单的id
					var ids = param.selected;
					// 已经有的订单数据
					var existeData = this.chooseData;
					// 当前页面已选订单的data
					var currentData = this.currentData;
					// 合并已有的data和当前data，得到所有已选订单对应的data
					mixData = existeData.concat(currentData);

					for (var i = 0; i<ids.length; i++) {
						var id = ids[i];
						for (var j = 0; j<mixData.length; j++) {
							var item = mixData[j];
							if (id === item.key) {
								result.push(item);
								break;
							}
						}
					}

					this.chooseData = result;
				},
				'setCurrentData': function(data){
					this.currentData = data;
					return this;
				},
				'setChooseData': function(value){
					this.chooseData = value;
					return this;
				},
				'getChooseData': function(){
					return this.chooseData;
				}
			};
			this.$data = null;

			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			// el.css('min-height', 750);
			var c = self.getConfig();

			$([
				'<div class="mt10">',
					'<div pub-name="adGrid" pub-mod="@base/highGrid.base" class="adGridCon"/>',
					'<label v-on:click="clickShowSelected" class="M-promotionConditionDealSpot">',
						'<input class="ml5" v-model="showSelected" type="checkbox"/>',
						'<span>' + LANG('显示已选') + '</span>',
					'</label>',
				'</div>'
			].join('')).appendTo(el);

			self.vm.mount();

			self.buildFromTemplate({
				adGrid: {
					'url':'deal/spots'
					,'cols': [
						{name: '_id', text: LANG('序号'), align: 'center', render: this.renderId},
						{name: 'Name', text: LANG('广告位'), align: 'center',width: 250},
						{name: 'DealId', text: LANG('所属订单ID'), align: 'center'},
						{name: 'Size', text: LANG('尺寸'), align: 'center'}
					]
					,'hasSearch': false
					,'hasExport': false
					,'hasRefresh': true
					,'hasAmount': false
					,'hasSubGrid': false
					,'hasTab': false
					,'hasFixedHeightBtn': false
					,'hasFilterSidebar': true
					,'reqType': 'websocket'
					,'sub_field': 'key'
					,'hasSelect': true
					,'pager': {'size': 10}
					,'key': 'key'
					// 发送选中事件
					,'eventSelect': true
					,'sidebar_config': {
						'height': 200,
						'items': [
							{'name': 'type', 'uri': 'modules/sideBarBase.radio', 'config': {
								'title': LANG('类型：'),
								'data': [
									{id: 0, name: LANG('全部')},
									{id: 2, name: LANG('私下竞价')},
									{id: 1, name: LANG('首选交易')},
									{id: 3, name: LANG('PDB')}
								],
								'value': 0
							}},
							{'name': 'deal', 'uri': 'modules/sideBarBase.dealRadio', 'config': {
								'title': LANG('订单：'),
								'data': [
									{id: 0, name: LANG('全部')},
									{id: 1, name: LANG('指定订单')}
								],
								'value': 0
							}}
						]
					}
				}
			});
		},
		afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
			var el = this.getDOM();
			el.find('.M-promotionConditionDealSpot').appendTo(el.find('.adGridCon .M-HighGridHeader'));
		},
		renderId: function(i, val){
			return val.toString ? val.toString() : val;
		},
		getValue: function(){
			var names = [];
			var string = '';
			var cs = this.$;
			// 用缓存的方式，不直接请求后端拿数据，是因为请求后端拿数据是异步的，getValue是同步的
			var ids = cs.adGrid.getSelectRowIds();
			var value = this.getSelectedData();

			value.forEach(function(item){
				if(item.Name){
					names.push(item.Name);
				}
			});

			var data = {
				'Data': ids,
				'Relation': 1,
				'Desc': '[' + names.join('、') + ']'
			};

			return data;
		},
		setValue: function(data){
			var self = this;
			self.$data = data;
			if(data && self.get('adGrid')){
				var cs = self.$;
				cs.adGrid.load();
				cs.adGrid.setSelectRowIds(data.Data);
				// 重新请求后端，得到已选订单对应的数据，缓存起来，用于保存后的订单名字显示
				pubjs.mc.send('deal/selectedSpots', {'keys': data.Data}, function(err, data){
					if (err) {
						pubjs.alert(err.message);
						return false;
					}
					self.$gridChooseData.setChooseData(data.items);
				});
			}

			return self;
		},
		eventShowSelected: function(){
			var cs = this.$;
			var vm = this.vm.$;
			var checked = vm.showSelected;
			var keys = [];

			// 勾上已选
			if (checked) {
				keys = cs.adGrid.getSelectRowIds();
				if (keys.length) { // 有选中
					cs.adGrid.reload({'keys': keys}, 'deal/selectedSpots');
				}
				else { // 没有选中
					cs.adGrid.setData([]);
				}
			}
			else {
				cs.adGrid.reload({'keys': keys}, 'deal/spots');
			}
		},
		onSidebarFilter: function(ev){
			var self = this;
			var param = {};

			util.each(ev.param, function(item, idx){
				var type = idx;
				var id = item.id;
				switch (type){
					case 'type':
						param.Type = +id;
						break;
					case 'deal':
						param.ids = item.data;
						break;
				}
			});

			self.$.adGrid.reload(param);
			return false;
		},
		reset: function(){
			var cs = this.$;
			this.vm.reset();
			cs.adGrid.setSelectRowIds([]);
			// reset筛选栏
			cs.adGrid.get('filter').eventClearResult();
			// reset请求的接口
			cs.adGrid.reload('', 'deal/spots', 1);
			this.$data = null;
			return this;
		},
		onMainPopwinOk: function(){
			this.$.adGrid.showPanel();
			return false;
		},
		onChangeSelect: function(ev){
			var modName = ev.name;
			if (modName === 'adGrid') {
				var cs = this.$;
				var ids = ev.param.selected;
				var currentData = cs.adGrid.getData(ids);

				this.$gridChooseData.setCurrentData(currentData);
				this.$gridChooseData.modChooseData(ev);
				return false;
			}
		},
		getSelectedData: function(){
			return this.$gridChooseData.getChooseData();
		}
	});
	exports.dealSpot = DealSpot;

	// 品牌版订单广告位
	var DealSpot2 = selectOnTab.main.extend({
		init: function(config){

			var cols =  [
				{name: '_id', text: LANG('序号'), align: 'center', render: this.renderId},
				{name: 'Name', text: LANG('广告位'), align: 'center',width: 250},
				{name: 'DealId', text: LANG('所属订单ID'), align: 'center'},
				{name: 'Size', text: LANG('尺寸'), align: 'center'}
			];

			config = pubjs.conf(config, {
				'url':'deal/spots',
				'tab': {
					'all': {
						'text': LANG('全部'),
						'uri': 'modules/selectOnTab.grid',
						'config': {
							'cols': cols
						}
					},
					'select': {
						'text': LANG('已选'),
						'uri': 'modules/selectOnTab.grid',
						'config': {
							'cols': cols
						}
					}
				}
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,renderId: function(i, val){
			return val.toString ? val.toString() : val;
		}
		,afterBuild: function(){
			this.getDOM().css('min-height', 500);
			this.Super('afterBuild', arguments);
			this.reload();
		}
		,getParentBidType: function(){
			return this.parent().$bidType;
		}
		,getParentSelectDeal: function(){
			return this.parent().$selectDeal;
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reload: function(){

			this.setParam({
				Type: this.getParentBidType(),
				ids: this.getParentSelectDeal()
			});
			this.load();

			return this;
		}
		,reset: function(){
			this.Super('reset', arguments);
			this.reload();

			return this;
		}
		,getValue: function(){
			var self = this;
			var data = {
				'Data': self.$selected,
				'Relation': 1,
				'Desc': '[' + self.$selected.join('、') + ']'
			};

			return data;
		}
		,setValue: function(data){
			// var self = this;
			// self.setData(data.Data);

			var self = this;
			var ids = data.Data;
			if(ids && ids.length){
				self.$selected = ids;

				self.get('tab/select').setParam({
					'spotIds': ids
				}, true).load();
			}

			self.updateTabTitle(self.$selected.length, 'select');
			self.$.tab.setData(self.$gridData, 'select');
			self.get('tab/all').setSelectRowIds(self.$selected);

			return self;
		}
		,validate: function(data){
			if(data && data.Data){
				if(!data.Data.length){
					pubjs.alert(LANG('至少需选择一个广告位'));
					return false;
				}
			}
			return true;
		}
	});
	exports.dealSpot2 = DealSpot2;


	// 交易订单
	var Deals = view.container.extend({
		init: function(config){
			var self = this;
			// 默认订单类型
			self.$defaultType = 3;
			self.$data = null;

			config = pubjs.conf(config, {
				url: 'deal/list',
				vModel: {
					'typeOps': [
						{'id': 3, 'name': LANG('PDB')},
						{'id': 1, 'name': LANG('首选交易')},
						{'id': 2, 'name': LANG('私下竞价')}
					],
					'type': this.$defaultType
				},
				vMethods: {
					'evDeleteAll': this.evDeleteAll,
					'evSelect': this.evSelect,
					'evChangeType': this.evChangeType
				}
			});

			this.createAsync('dealPopwin', 'campaign/modules/select.popwin', {
				'title': LANG('选择订单'),
				'url': 'deal/list',
				'grid_mod': 'campaign/modules/select.dealGrid',
				'auto_load': false,
				'size': 'l',
				'param': {
					'Type': self.$defaultType
				}
			});
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div>',
					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('交易类型：') + '</label>',
						'<div class="group-content">',
							'<label v-for="item in typeOps" class="mr15">',
								'<input type="radio" v-bind:value="item.id" v-model="type" v-on:click="evChangeType(item.id)"/>',
								'{{item.name}}',
							'</label>',
						'</div>',
					'</div>',

					'<div class="M-formConGroup">',
						'<label class="group-label">' + LANG('订单：') + '</label>',
						'<div class="group-content">',
							'<span class="btn btn-danger mr10" v-on:click="evDeleteAll">'+ LANG('删除所有') +'</span>',
							'<span class="btn btn-default mr10" v-on:click="evSelect">'+ LANG('选择订单') +'</span>',
							'<div class="mt20" pub-name="dealList" pub-mod="@base/grid.baseNoDate"/>',
						'</div>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				// 广告位列表
				dealList: {
					'url': 'deal/list',
					'auto_load': false,
					'reqType': 'websocket',
					'cols': [
						{name: "_id", text:LANG("ID"), width:50},
						{name: 'Name', text:LANG("订单名称"), width:100},
						{name: 'Time', text: LANG('订单时间'), width:100},
						{name: 'Price', text: LANG('订单价格'), width:100},
						{name: 'Status', text:LANG('状态'),  align:'center'},
						{name: 'channelName', text:LANG('渠道'), align:'center'},
						{name: 'SpotsInfo', text:LANG('广告位数量'), align:'center'},
						{type: 'op', width: 50, html:'<a href="#" data-op="remove">' + LANG('删除') + '</a>'}
					],
					'opClick': true,
					'default_sort': false,
					'hasSearch': false,
					'hasSubGrid': false,
					'hasAmount': false,
					'hasTab': false,
					'hasExport': false,
					'pager': {
						'size': 10,
						"showSizeTypes": false
					}
				}

			});

			this.vm.mount();
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,evDeleteAll: function(){
			var cs = this.$;
			this.$ids = [];
			cs.dealList.setParam({'ids': ''});
			this.resetDealList();
			cs.dealPopwin.setParam({'ids': []});
			return this;
		}
		,evSelect: function()
		{
			this.$.dealPopwin.reset().setData(this.$ids).show();
		}
		,evChangeType: function(new_type)
		{
			var self = this;
			var old_type = +self.vm.getCopy('type');

			if (old_type != new_type)
			{
				pubjs.confirm(LANG('仅能选择一个类型的订单，选择其它类型将清空已选择的订单，确定选择其它？'), function(isOk)
				{
					// 如果重置，则将id重置
					if (isOk)
					{
						self.$ids = [];
						self.$.dealList.setParam({'Type': +new_type, 'ids': ''});
						self.resetDealList();
						self.$.dealPopwin.setParam({'Type': +new_type, 'ids': []});
					}
					// 如果不重置，则选择会原来的类型
					else
					{
						self.vm.$.type = old_type;
					}
				});
			}
		}
		,getValue: function()
		{
			var cs = this.$;
			var ids = this.$ids || [];
			var type = this.vm.$.type;
			var type_map = {
				'3': LANG('PDB'),
				'1': LANG('首选交易'),
				'2': LANG('私下竞价')
			}
			var data = {
				'Data':{
					'Ids': ids,
					'Type': +type
				},
				'Desc': type_map[type] + ' 且 订单：[' +ids.toString() + ']'
			};

			return util.clone(data);
		}
		,setValue: function(data)
		{
			this.$data = util.clone(data);
			if(data && this.get('dealList')){
				var dealData = data.Data;
				this.$ids = dealData.Ids;
				this.vm.$.type = dealData.Type;

				this.$.dealPopwin.setParam({'Type': +dealData.Type});
				this.load();
			}

			return this;
		}
		,reset: function()
		{
			this.resetDealList();
			this.vm.reset();
			this.$data = null;

			return this;
		}
		,resetDealList: function()
		{
			this.$.dealList.setData([]);
			this.$.dealList.setPage(1, 10, 0);
			var pager = this.get('dealList/pager').setup({
				'page': 1,
				'total': 0,
				'size': 10
			});
		}
		,onListOpClick: function(ev)
		{
			var param = ev.param;
			if (param.op == 'remove')
			{
				// 删除单条记录
				var index = param.index;
				var id = param.data._id;
				// 删除列表的对应数据
				this.$.dealList.removeRow(index);

				// 删除id
				if (this.$ids && (this.$ids.indexOf(id) != -1))
				{
					this.$ids.splice(this.$ids.indexOf(id), 1);
					this.$.dealList.setParam({'ids': this.$ids.join(',')});
				}
			}

			return false;
		}
		,onDialogOk: function(ev)
		{
			var ids = [];
			util.each(this.$.dealPopwin.getData() || [], function(id)
			{
				if (+id)
				{
					ids.push(+id);
				}
			}, this);

			this.$ids = ids;
			this.$.dealPopwin.hide();
			// 拉取订单数据
			this.load();
			return false;
		}
		,load: function()
		{
			var ids = this.$ids || [];
			var url = this.getConfig('url');

			if (!ids || !ids.length)
			{
				this.$.dealList.setData([]);
				return false;
			}

			this.$.dealList.setParam({
				'Type': +this.vm.$.type,
				'ids': ids.join(',')
			}).load();
		}
	});
	exports.deals = Deals;

	// 媒体广告位
	var MediaSpot = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {

			});

			// 缓存后端返回来的ids
			this.$ids = [];
			this.$data = null;
			this.createAsync('adPopwin', 'promotion/popwin/adImport.adImport');
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div>',
					'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
					// '<div>' + LANG('广告位：') + '</div>',
					'<div class="M-formConGroup">',
						// '<label class="fl">' + LANG('广告位：') + '</label>',
						'<div class="">',
							'<span pub-name="importBtn" pub-mod="@base/common/input.button"/>',
							'<span pub-name="deleteBtn" pub-mod="@base/common/input.button"/>',
							'<div class="mt20" pub-name="adList" pub-mod="@base/grid.baseNoDate"/>',
						'</div>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				deleteBtn: {
					'class': 'btn btn-danger mr10',
					'value': LANG('删除所有')
				},
				importBtn: {
					'class': 'btn btn-default mr10',
					'value': LANG('导入广告位')
				},
				// 广告位列表
				adList: {
					'cols': [
						{type: 'id', width: 80},
						{name: '_id', text: LANG('媒体广告位ID'), align: 'left'},
						{name: 'Name', text: LANG('广告位名称'), align: 'left'},
						{name: 'AdxId', text: LANG('渠道'), align: 'left', render: 'renderChannel'},
						{name: 'Size', text: LANG('广告位尺寸'), align: 'left'},
						{type: 'op', width: 50, html:'<a href="#" data-op="remove">' + LANG('删除') + '</a>'}
					],
					'opClick': true,
					'default_sort': false,
					'hasSearch': false,
					'hasSubGrid': false,
					'hasAmount': false,
					'hasTab': false,
					'hasExport': false,
					'pager': {'size': 10},
					'url':'spot/listByIds',
					'auto_load': false,
					'reqType': 'websocket'
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,renderChannel: function(val, data){
			var adxIds = pubjs.config('exchange');
			if (data) {
				for (var i = 0; i<adxIds.length; i++) {
					var item = adxIds[i];
					if (+data === +item.id) {
						return item.name;
					}
				}
			}
			else {
				return this;
			}
		}
		,onInputClick: function(ev){
			var name = ev.name;
			switch (name){
				case 'deleteBtn':
					this.deleteAll();
					break;
				case 'importBtn':
					this.$.adPopwin.reset().show();
					break;
			}
		}
		,onAdImportOk: function(ev){
			var cs = this.$;
			var ids = util.clone(this.$ids);
			var data = ev.param.items;
			var currentIds = [];

			data.forEach(function(item){
				var id = item._id.toString ? item._id.toString() : item._id;
				currentIds.push(id);
			});

			// 直接用将两个数组用concat的话，只能合并，不能去重，因为他们的_id不是数字，是int64
			if (currentIds) {
				for (var i = currentIds.length-1; i>=0; i--) {
					var currentId = currentIds[i];
					for (var j = 0; j<ids.length; j++) {
						var idsString = ids[j].toString ? ids[j].toString() : ids[j];
						if (currentId === idsString) {
							currentIds.splice(i, 1);
							break;
						}
					}
				}
				this.$ids = currentIds.concat(ids);
			}
			else{
				pubjs.alert(LANG('找不到相应的广告位'));
				return false;
			}
			// 表格再次请求接口spot/listByIds，以便分页
			cs.adList.setParam({'ids': this.$ids.join(',')}).load();

			return false;
		}
		,deleteAll: function(){
			var cs = this.$;
			cs.adList.setData([]);
			// 清除缓存的ids
			this.$ids = [];

			return this;
		}
		,getValue: function(){
			var cs = this.$;
			var adIds = this.$ids;

			var data = {
				'Data': adIds,
				'Relation': cs.relation.getValue(),
				'Desc': '[' +adIds.join('、') + ']'
			};

			return data;
		}
		,setValue: function(data){
			this.$data = data;

			if(data && this.get('relation') && this.get('adList')){
				var self = this;
				var cs = self.$;
				cs.relation.setValue(data.Relation);
				// 更新缓存的已导入的数据
				this.$ids = data.Data;
				cs.adList.setParam({'ids': data.Data}, true).load();
			}

			return self;
		}
		,reset: function(){
			var cs = this.$;
			// 重置缓存的导入的数据
			this.$ids = [];
			// 选择关系的重置
			cs.relation.reset();
			// 表格数据重置会空
			cs.adList.setData([]);
			this.$data = null;
			return this;
		}
		,onListOpClick: function(ev){
			var param = ev.param;
			var op = param.op;
			if (op === 'remove') {
				// 删除单条记录
				var index = param.index;
				this.$.adList.removeRow(index);
				// 删除缓存里面对应的那条数据
				var data = param.data;
				var id = data._id.toString ? data._id.toString() : data._id;
				var ids = util.clone(this.$ids);
				for (var i = 0; i<ids.length; i++) {
					var item = ids[i].toString ? ids[i].toString() : ids[i];
					if (id === item) {
						ids.splice(i, 1);
						break;
					}
				}

				this.$ids = ids;
			}

			return false;
		}
		,validate: function(data){
			if(data && data.Data){
				if(!data.Data.length){
					pubjs.alert(LANG('至少需选择一个广告位'));
					return false;
				}
			}
			return true;
		}
	});
	exports.mediaSpot = MediaSpot;

	// 投放地区
	var Zone = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 500);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('选择地区：') + '</label>',
					'<div class="group-content" pub-name="zone" pub-mod="modules/newZone.base"/>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate();
		}
		,reset: function(){
			this.$.relation.reset();
			this.$.zone.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data){
			this.$data = data;
			if(data && this.get('relation') && this.get('zone')){
				this.$.relation.setValue(data.Relation);
				this.$.zone.setData(data.Data);
			}
			return this;
		}
		,getValue: function(){
			var list = this.$.zone.getDesc();
			var zoneData = this.$.zone.getData();
			var data = {
				'Data': zoneData,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return data;
		},
		onDataLoadEnd: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
			return false;
		},
		validate: function(){
			var data = this.getValue();
			if(!data.Data.length){
				pubjs.alert(LANG('至少需选择一个地区'));
				return false;
			}
			return true;
		}
	});
	exports.zone = Zone;

	// 投放日期
	var Time = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('投放时间：') + '</label>',
					'<div class="group-content">',
						'<span pub-name="startTime" pub-mod="@base/common/date.datePickerNew"/>',
						'<span class="ml10 mr10 valign-m">'+LANG('至')+'</span>',
						'<span pub-name="endTime" pub-mod="@base/common/date.datePickerNew"/>',
					'</div>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				// 投放日期开始
				startTime: {
					value: util.date('Y-m-d'),
					buttons: null,
					width: 100
				},
				// 投放结束日期
				endTime: {
					min: util.date('Y-m-d'),
					showDialogButton: true,
					width: 100
				},
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		// 投放日期
		,onDateChange: function(ev){
			var cs = this.$;
			switch (ev.from){
				case cs.startTime:
					cs.endTime.setup({min: ev.param});
					break;
				case cs.endTime:
					cs.startTime.setup({max: ev.param});
					break;
			}
			return false;
		}
		,reset: function(){
			this.$.relation.reset();
			this.$.startTime.setData(util.date('Y-m-d'));
			this.$.endTime.setData(null);
			this.$data = null;
			return this;
		}
		,setValue: function(data){
			this.$data = data;
			if(data && this.get('relation') && this.get('startTime') && this.get('endTime')){
				this.$.relation.setValue(data.Relation);
				this.$.startTime.setData(data.Data.StartTime || util.date('Y-m-d'));
				this.$.endTime.setData(data.Data.EndTime);
			}
			return this;
		}
		,getValue: function(){
			var cs = this.$;
			var data = {
				'StartTime': cs.startTime.getData(),
				'EndTime': cs.endTime.getData() || 0
			}
			var data = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' + util.date("Y-m-d", data.StartTime) + LANG(' 至 ') +  (data.EndTime ? util.date("Y-m-d", data.EndTime) : LANG('不限')) +']'
			};
			return data;
		}
		,validate: function(){
			return true;
		}
	});
	exports.time = Time;

	// 投放日程
	var TimeSet = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				vModel: {
					'_TimeSetRadio': 1
				}
			});

			this.$weekMap = { // 星期map
				'0': LANG('星期日'),
				'1': LANG('星期一'),
				'2': LANG('星期二'),
				'3': LANG('星期三'),
				'4': LANG('星期四'),
				'5': LANG('星期五'),
				'6': LANG('星期六')
			};
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 500);

			$([
				'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',

				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('投放时段：') + '</label>',
					'<div class="group-content">',
						'<div class="M-formSectionItem">',
							'<label>',
								'<input type="radio" v-model="_TimeSetRadio" value="1" class="mr5">',
								'<span>'+LANG('全天候展示广告')+'</span>',
							'</label>',
							'<label>',
								'<input type="radio" v-model="_TimeSetRadio" value="2" class="mr5">',
								'<span>'+ LANG('指定时间') +'</span>',
							'</label>',
						'</div>',
						'<div v-show="_TimeSetRadio!=1" class="mt10" pub-name="detail" pub-mod="modules/timeZone.base"/>',
					'</div>',
				'</div>'

			].join('')).appendTo(el);

			self.vm.mount();

			self.buildFromTemplate();
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function(){
			this.vm.reset();
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data){
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				var timeSet = data.Data;
				this.vm.$._TimeSetRadio = timeSet.Type;
				this.$.detail.setData(timeSet.DayHour);
			}
			return this;
		}
		,getValue: function(){
			var Timeset = {
				'Type': +this.vm.get('_TimeSetRadio'),
				// 1为全天投放，2为指定时间
				'DayHour': this.$.detail.getData()
			}
			var desc = [];
			var date = Timeset.DayHour;
			if(Timeset.Type != 1){
				for(var i in date){
					desc.push(this.$weekMap[i] + '：' + this._formatTime(date[i]));
				}
			}else{
				desc.push(LANG('全天候展示广告'));
			}

			var data = {
				'Data': Timeset,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' + desc.join('；') + ']'
			};
			return data;
		}
		,_formatTime: function(data){
			data = data.slice();
			var first = data.shift(),
				text = first + '~',
				last = first + 1,
				list = [],
				now;
			for( var i = 0; i < data.length; i++ ) {
				now = data[i];
				if( now != last ) {
					text += last;
					list.push( text );
					text = now + '~';
				}
				last = now +1;
			}
			text += last;
			list.push( text );
			return list.join(', ');
		}
		,validate: function(){
			var data= this.getValue();

			if(data.Data.Type == 2 && util.isEmptyObject(data.Data.DayHour)){
				pubjs.alert(LANG('至少需选择一个时段'));
				return false;
			}
			return true;
		}
	});
	exports.timeSet = TimeSet;

	// 自有人群
	var NPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择自有人群：') + '</div>',
				'<div class="mt10" pub-name="people" pub-mod="modules/treeSelect.popwin"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				people: {
					'showTitle': false,
					'isPopwin': false,
					'hasLogic': true,
					'param': {
						'url': 'category/peopleTotal',
						'param': {
							'ChannelId': 10009,
							'Layer': 5
						}
					},
					'key': 'BdxId'
				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.people.load();
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.people.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('people')){
				this.$.relation.setValue(data.Relation);
				this.$.people.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.people.getValue();
			util.each(data, function(item, idx){
				if(item && item.texts){
					if(idx){
						list.push(item.logic == 'or' ? LANG('或') : LANG('且'));
					}
					list.push(item.texts);
				}
			});
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join(' ') + ']'
			};
			return result;
		}
		,onTreePopDataLoaded: function() {
			if(this.$data){
				this.setValue(this.$data);
			}
		}
	});
	exports.nPeople = NPeople;

	// IP地址
	var IpSections = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('IP地址段：') + '</label>',
					'<div class="group-content" pub-name="detail" pub-mod="campaign/modules/ipaddress.base"/>',
				'</div>',
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {

				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.setData(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var data = this.$.detail.getData();
			var desc = [];
			var list = [];

			util.each(data, function(item){
				list.push(item);
				desc.push(item.Start + '~' + item.End);
			});

			var result = {
				'Data': list,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('、') + ']'
			};
			return result;
		}
		,validate: function(){
			var data = this.getValue();
			var re = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
			var error = false;

			util.each(data.Data, function(item){
				if(re.test(item.Start) && re.test(item.End)){

				}else{
					error = true;
				}

			});

			if(!data.Data.length){
				pubjs.alert(LANG('至少需添加一个地址段'));
				return false;
			}

			if(error){
				pubjs.alert(LANG('请输入正确的IP地址格式或IP地址范围'));
				return false;
			}

			return true;
		}
	});
	exports.ipSections = IpSections;

	// 上网场景
	var Scene = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择上网场景：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="campaign/modules/netScence.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {

				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var data = this.$.detail.getValue();
			var list = this.$.detail.getDesc();

			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
	});
	exports.scene = Scene;

	// 百度指数
	var HotWord = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 750);

			$([
				'<div>' + LANG('选择百度指数：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="campaign/modules/hotWord.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {

				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('detail')){
				this.$.detail.setData(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var data = this.$.detail.getData();
			var desc = [];
			var target = {
				1: LANG('国家'),
				2: LANG('省份'),
				3: LANG('城市')
			};
			var changeType = {
				1: LANG('上升'),
				2: LANG('下降'),
				3: LANG('上升或下降')
			}

			util.each(data, function(item){
				if(item){
					desc.push([
						LANG('关键词"')+item.Words.join('、') +'"：',
						LANG('当所投%1最近%2天，百度搜索指数上升≥%3% ，且搜索指数≥%4时，之后%5天持续投放广告', target[item.Target],item.Change.RecentCount,item.Change.ChangeCount,item.Change.ChangeLimit,item.OpenDays)
					].join(''));
				}
			});

			var result = {
				'Data': data,
				'Relation': 1,
				'Desc': '[' +desc.join('；') + ']'
			};
			return result;
		}
	});
	exports.hotWord = HotWord;

	// 百度tag_id
	var CustomizedUserTag = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				vModel: {
					'bes_tag': ''
				}
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10">' + LANG('选择百度tag_id：') + '</div>',
				'<input type="text" v-model="bes_tag" class="mt20 w300">'
			].join('')).appendTo(el);

			self.vm.mount();

			self.buildFromTemplate({
			});
		}
		,afterBuildTemplate: function(){
		}
		,reset: function() {
			this.vm.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data){
				this.vm.$.bes_tag = data.Data.AmsTagList;
			}
			return this;
		}
		,getValue: function() {
			var data = this.vm.$.bes_tag;

			var result = {
				'Data': {AmsTagList: data},
				'Relation': 1,
				'Desc': '[' + data + ']'
			};
			return result;
		}
	});
	exports.customizedUserTag = CustomizedUserTag;

	// 视频定向
	var VideoDirect = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 700);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择视频定向：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="@base/common/base.tab"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {
					'reqMethod': 'websocket',
					'list': {
						'type':{
							'text': LANG('按条件'),
							'module': 'campaign/modules/videoDirect.type',
							'class': 'P-campaignEditBodyVideoDirect'
						},
						'word':{
							'text': LANG('搜索'),
							'module': 'campaign/modules/videoDirect.word',
							'class': 'P-campaignEditBodyVideoDirect'
						}
					},
					'css': {
						'width': 950
					}
				}
			});
		}
		,afterBuildTemplate: function(){
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				var videoDirectWord = this.$.detail.get('word');
				var videoDirectType = this.$.detail.get('type');

				videoDirectWord.load(data.Data.WordIds);
				videoDirectType.setData(data.Data.CategoryIds);

			}
			return this;
		}
		,getValue: function() {
			var videoDirectWord = this.$.detail.get('word');
			var videoDirectType = this.$.detail.get('type');
			var data = {
				'Status': true,
				'CategoryIds': videoDirectType.getData(),
				'WordIds': videoDirectWord.getValue()
			};
			var typeDesc = LANG('类型：') + videoDirectType.getDesc().join('、');
			var wordDesc = LANG('搜索：') + videoDirectWord.getDesc().join('、');

			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' + typeDesc + '；' + wordDesc + ']'
			};
			return result;
		}
		,onDataLoadEnd: function(ev){
			if(this.$data){
				this.setValue(this.$data);
			}
			return false;
		}
	});
	exports.videoDirect = VideoDirect;

	// 屏次
	var Screen = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('选择屏次：') + '</label>',
					'<div class="group-content" pub-name="checkbox" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				checkbox: {
					'reqType': 'websocket',
					'url': 'category/screen',
					'id': 'BdxId',
					'name': 'Name',
					'width': 100
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.checkbox.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('checkbox')){
				this.$.relation.setValue(data.Relation);
				this.$.checkbox.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var desc = this.$.checkbox.getDesc();
			var data = this.$.checkbox.getValue();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('、') + ']'
			};
			return result;
		}
		,validate: function(data){
			if(data.Data && !data.Data.length){
				pubjs.alert(LANG('至少需选择一个屏次'));
				return false;
			}
			return true;
		}
	});
	exports.screen = Screen;

	// 展现形式
	var ViewType = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				vModel: {

				}
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('展现形式：') + '</label>',
					'<div class="group-content" pub-name="checkbox" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>'
			].join('')).appendTo(el);

			self.vm.mount();

			self.buildFromTemplate({
				checkbox: {
					// 'prefix': 'adsGroupEditdisplay'
					// ,'url': 'spot/displayType'
					'full': true,
					// ,'autoLoad': true
					'operator': true,
					// ,'hasSearch': true
					'silent': false,
					// ,'items': [
					// 	{'id': 1, 'name' : '固定广告位'}
					// 	,{'id': 5, 'name' : '弹窗广告位'}
					// 	,{'id': 7, 'name' : '背投广告位'}
					// 	,{'id': 11, 'name':'视频贴片'}
					// 	,{'id': 12, 'name':'视频暂停'}
					// 	,{'id': 13, 'name':'悬停'}
					// 	,{'id': 101, 'name':'无线开屏'}
					// 	,{'id': 102, 'name':'无线弹窗'}
					// 	,{'id': 103, 'name':'无线横幅'}
					// 	,{'id': 104, 'name':'无线墙'}
					// 	,{'id': 105, 'name':'无线文字链'}
					// 	,{'id': 106, 'name':'无线视频贴片'}
					// 	,{'id': 107, 'name':'无线视频暂停'}
					// 	,{'id': 201, 'name':'固定(移动网页)'}
					// ]
					'reqType': 'websocket',
					'url': 'category/viewType',
					'id': 'BdxId',
					'name': 'Name'
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.checkbox.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('checkbox')){
				this.$.relation.setValue(data.Relation);
				this.$.checkbox.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var desc = this.$.checkbox.getDesc();
			var data = this.$.checkbox.getValue();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('、') + ']'
			};
			return result;
		}
		,validate: function(data){
			if(data.Data && !data.Data.length){
				pubjs.alert(LANG('至少需选择一个展现形式'));
				return false;
			}
			return true;
		}
	});
	exports.viewType = ViewType;

	// WEB条件-------------------------

	// 三方人群
	var TBPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 600);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择人群：') + '</div>',
				'<div class="mt10" pub-name="people" pub-mod="modules/treeSelect.popwin"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				people: {
					'showTitle': false,
					'isPopwin': false,
					'hasLogic': true,
					'param': {
						'url': 'category/peopleTotal',
						'param': {
							'ChannelId': 10004
						}
					}
				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.people.load();
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.people.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation')){
				this.$.relation.setValue(data.Relation);
				this.$.people.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.people.getValue();
			util.each(data, function(item, idx){
				if(item && item.texts){
					if(idx){
						list.push(item.logic == 'or' ? LANG('或') : LANG('且'));
					}
					list.push(item.texts);
				}
			});
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
		,onTreePopDataLoaded: function() {
			if(this.$data){
				this.setValue(this.$data);
			}
		}
	});
	exports.tbPeople = TBPeople;

	// 秒针人群
	var MZPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 600);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择人群：') + '</div>',
				'<div class="mt10" pub-name="people" pub-mod="modules/treeSelect.popwin"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				people: {
					'showTitle': false,
					'isPopwin': false,
					'hasLogic': true,
					'param': {
						'url': 'category/people',
						'param': {
							'ChannelId': 10001
						}
					}
				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.people.load();
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.people.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('people')){
				this.$.relation.setValue(data.Relation);
				this.$.people.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.people.getValue();
			util.each(data, function(item, idx){
				if(item && item.texts){
					if(idx){
						list.push(item.logic == 'or' ? LANG('或') : LANG('且'));
					}
					list.push(item.texts);
				}
			});
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
		,onTreePopDataLoaded: function() {
			if(this.$data){
				this.setValue(this.$data);
			}
		}
	});
	exports.mzPeople = MZPeople;

	// 其他人群
	var BDXPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 600);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择人群：') + '</div>',
				'<div class="mt10" pub-name="people" pub-mod="modules/treeSelect.popwin"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				people: {
					'showTitle': false,
					'isPopwin': false,
					'hasLogic': true,
					'param': {
						'url': 'PDMP/bdxPeople',
						'param': {
							'ChannelId': 168
						}
					}
				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.people.load();
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.people.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('people')){
				this.$.relation.setValue(data.Relation);
				this.$.people.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.people.getValue();
			util.each(data, function(item, idx){
				if(item && item.texts){
					if(idx){
						list.push(item.logic == 'or' ? LANG('或') : LANG('且'));
					}
					list.push(item.texts);
				}
			});
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
		,onTreePopDataLoaded: function() {
			if(this.$data){
				this.setValue(this.$data);
			}
		}
	});
	exports.bdxPeople = BDXPeople;

	// 重定向
	var Character = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div>' + LANG('选择重定向：') + '</div>',
				'<div class="mt10" pub-name="character" pub-mod="campaign/modules/character.newPDMP"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				character: {
					'url': 'PDMP/characters',
					'param': {
						'Type': 1,
						'runstatus': 1
					}
				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.character.load();
		}
		,reset: function() {
			this.$.character.reset();
			this.$data = null;
			return this;
		}
		,getValue: function() {
			var data = this.$.character.getValue();

			// 构建渲染的字符串
			var cookieString = redirectString(data.Cookie, 'Cookie');
			var IpString = redirectString(data.Ip, 'Ip');
			var string = cookieString.concat(IpString);

			var result = {
				'Data': data,
				'Relation': 1,
				'Desc': '[' + string.join(LANG(' 且 ')) + ']'
			};
			return result;
		}
		,setValue: function(data){
			this.$data = data;

			if(data && this.get('character')){
				this.$.character.setValue(data.Data);
			}
			return this;
		}
		,onDataLoadEnd: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
			return false;
		}
		,validate: function(data){
			// 验证重定向
			var character = data.Data;
			if(character){
				var notExists;
				var characterIp = character.Ip || {};
				var characterCookie = character.Cookie || {};
				var hasIpInclude = characterIp.Include && characterIp.Include.length;
				var hasIpExclude = characterIp.Exclude && characterIp.Exclude.length;
				var hasCookieInclude = characterCookie.Include && characterCookie.Include.length;
				var hasCookieExclude = characterCookie.Exclude && characterCookie.Exclude.length;
				notExists = !hasIpInclude && !hasIpExclude && !hasCookieInclude && !hasCookieExclude;

				if(notExists){
					pubjs.alert(LANG('请指定重定向人群标签！'));
					return false;
				}

				//人群标签限制每组数据最大为50个
				var characterLimitError = [];
				var characterType = ['IP','Cookie','Device'];
				var InOrExType = ['Include','Exclude'];
				util.each(characterType, function(item){
					if (character[item]) {
						util.each(InOrExType, function(type){
							if (character[item][type].length > 50) {
								var tmpError = {};
								tmpError['type'] = type;
								tmpError['name'] = item;
								characterLimitError.push(tmpError);
							}
						});
					}
				});
				var characterMap = {
					'IP': LANG('IP人群标签'),
					'Cookie': LANG('Cookie人群标签'),
					'Device': LANG('设备人群标签'),
					'Include': LANG('包含'),
					'Exclude': LANG('排除')
				}
				if(characterLimitError.length){
					var error = characterLimitError[0];
					pubjs.alert(LANG('重定向选择的%1%2数量超过最大限制数量,最大限制数量为50个', characterMap[error['type']], characterMap[error['name']]));
					return false;
				}
			}

			return true;
		}
	});
	exports.character = Character;

	// 客户端
	var Client = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignOrientDeciveAppDecive'
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 750);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',

				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('操作系统：') + '</label>',
					'<div class="group-content" pub-name="os" pub-mod="campaign/modules/deviceType.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('浏览器：') + '</label>',
					'<div class="group-content" pub-name="browser" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('系统语言：') + '</label>',
					'<div class="group-content" pub-name="language" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				'os': {
					'reqType': 'websocket',
					'url': 'category/osPc',
					'id': 'BdxId',
					'name': 'Name',
					'Type': 'os'
					// 'width': 100,
				},
				'browser': {
					'reqType': 'websocket',
					'url': 'category/browserPc',
					'id': 'BdxId',
					'name': 'Name',
					// 'width': 100,
				},
				'language': {
					'reqType': 'websocket',
					'url': 'category/systemLang',
					'id': 'BdxId',
					'name': 'Name',
					// 'width': 100,
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			if(this.get('os')){
				this.$.os.reset();
			}
			if(this.get('browser')){
				this.$.browser.reset();
			}
			if(this.get('language')){
				this.$.language.reset();
			}
			this.$data = null;
			return this;
		}
		,setValue: function(data){
			var value = {};
			var Data = data.Data;
			this.$data = data;

			if(data){
				if(this.get('relation')){
					this.$.relation.setValue(data.Relation);
				}
				if(this.get('os')){
					this.$.os.setData(Data.OSType);
				}
				if(this.get('browser')){
					this.$.browser.setValue(Data.BrowserType);
				}
				if(this.get('language')){
					this.$.language.setValue(Data.Language);
				}
			}

			return this;
		}
		,getValue: function(){
			var os = this.$.os.getData();
			var browser = this.$.browser.getValue();
			var language = this.$.language.getValue();

			var os_desc = this.$.os.getDesc(os.os);
			var browser_desc = this.$.browser.getDesc();
			var language_desc = this.$.language.getDesc();

			var desc = [];

			if(os_desc.length){
				desc.push(os_desc.join('、'));
			}
			if(browser_desc.length){
				desc.push(browser_desc.join('、'));
			}
			if(language_desc.length){
				desc.push(language_desc.join('、'));
			}

			var tmp = {
				'OSType': os.os || null,
				'BrowserType': browser || null,
				'Language': language || null
			}

			var result = {
				'Data': tmp,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('；')+ ']'
			};
			return result;
		}
		,validate: function(data){
			if(data){
				if(!data.Data.OSType.length && !data.Data.BrowserType.length && !data.Data.Language.length){
					pubjs.alert(LANG('请至少需选择一个筛选条件'));
					return false;
				}
			}
			return true;
		}
	});
	exports.client = Client;

	// 温度设置
	var Temperature = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择温度：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="campaign/modules/temperature.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function (data){
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.setData(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.detail.getData();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
	});
	exports.temperature = Temperature;

	// 湿度设置
	var HumidityLevels = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择适度：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="modules/checkBoxGroup.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {
					'items': _convertMapToItems(pubjs.config('humidity'), true)
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function (data){
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.setData(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.detail.getData();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
	});
	exports.humidityLevels = HumidityLevels;

	// 空气指数
	var ApiLevels = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择空气指数：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="modules/checkBoxGroup.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {
					'items': _convertMapToItems(pubjs.config('AQI'), true)
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function (data){
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.setData(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.detail.getData();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
	});
	exports.apiLevels = ApiLevels;

	// 温差设置
	var TemperatureDiff = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择温差：') + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="campaign/modules/temperatureDiff.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: {
					'css': {
						'width': 950
					}
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function (data){
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.setData(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.detail.getData();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
	});
	exports.temperatureDiff = TemperatureDiff;

	// 页面关键词
	var PageKeyword = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'title': LANG('选择页面关键词：'),
				'detail': {
					'css': {
						'width': 950
					}
				}
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			var c = self.getConfig();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + c.title + '</div>',
				'<div class="mt10" pub-name="detail" pub-mod="campaign/modules/pageKeyword.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				detail: c.detail
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.detail.reset();
			this.$data = null;
			return this;
		}
		,setValue: function (data){
			this.$data = data;
			if(data && this.get('relation') && this.get('detail')){
				this.$.relation.setValue(data.Relation);
				this.$.detail.load(data.Data).setValue(data.Data);

			}
			return this;
		}
		,getValue: function() {
			var list = this.$.detail.getDesc();
			var data = this.$.detail.getValue();
			data['Status'] = true;

			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
	});
	exports.detail = PageKeyword;

	// 用户关键词
	var UserKeyword = PageKeyword.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'title': LANG('选择用户关键词：'),
				'detail': {
					'listType': 'userKeyword',
					'css': {
						'width': 950
					}
				}
			});
			this.Super('init', arguments);
		}
	});
	exports.userKeyword = UserKeyword;


	//APP条件---------------------------

	// 其他人群
	var APP_BdxPeople = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 600);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('选择人群：') + '</div>',
				'<div class="mt10" pub-name="people" pub-mod="modules/treeSelect.popwin"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				people: {
					'showTitle': false,
					'isPopwin': false,
					'hasLogic': true,
					'param': {
						'url': 'PDMP/bdxPeople',
						'param': {
							'ChannelId': 168,
							'isMobile': true
						}
					}
				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.people.load();
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.people.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('people')){
				this.$.relation.setValue(data.Relation);
				this.$.people.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var list = [];
			var data = this.$.people.getValue();
			util.each(data, function(item, idx){
				if(item && item.texts){
					if(idx){
						list.push(item.logic == 'or' ? LANG('或') : LANG('且'));
					}
					list.push(item.texts);
				}
			});
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +list.join('、') + ']'
			};
			return result;
		}
		,onTreePopDataLoaded: function() {
			if(this.$data){
				this.setValue(this.$data);
			}
		}
	});
	exports.app_BdxPeople = APP_BdxPeople;

	// 重定向
	var APP_Character = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div>' + LANG('选择重定向：') + '</div>',
				'<div class="mt10" pub-name="character" pub-mod="campaign/modules/character.newPDMP"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				character: {
					'showTitle': false,
					'isPopwin': false,
					'hasLogic': true,
					'url': 'PDMP/characters',
					'param': {
						'Type': 4,
						'runstatus': 1
					}

				}
			});
		}
		,afterBuildTemplate: function(){
			this.$.character.load();
		}
		,reset: function() {
			this.$.character.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('character')){
				this.$.character.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var data = this.$.character.getValue();

			// 构建渲染的字符串
			if (data.Device) {
				var string = redirectString(data.Device, 'Device');
			}

			var result = {
				'Data': data,
				'Relation': 1,
				'Desc': '[' + string.join(LANG(' 且 ')) + ']'
			};
			return result;
		}
		,onDataLoadEnd: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
			return false;
		}
		,validate: function(data){
			// 验证重定向
			var character = data.Data;
			if(character){
				var notExists;
				var characterDevice = character.Device || {};
				var hasDeviceInclude = characterDevice.Include && characterDevice.Include.length;
				var hasDeviceExclude = characterDevice.Exclude && characterDevice.Exclude.length;
				notExists = !hasDeviceExclude && !hasDeviceInclude;

				if(notExists){
					pubjs.alert(LANG('请指定重定向人群标签！'));
					return false;
				}

				//人群标签限制每组数据最大为50个
				var characterLimitError = [];
				var characterType = ['IP','Cookie','Device'];
				var InOrExType = ['Include','Exclude'];
				util.each(characterType, function(item){
					if (character[item]) {
						util.each(InOrExType, function(type){
							if (character[item][type].length > 50) {
								var tmpError = {};
								tmpError['type'] = type;
								tmpError['name'] = item;
								characterLimitError.push(tmpError);
							}
						});
					}
				});
				var characterMap = {
					'IP': LANG('IP人群标签'),
					'Cookie': LANG('Cookie人群标签'),
					'Device': LANG('设备人群标签'),
					'Include': LANG('包含'),
					'Exclude': LANG('排除')
				}
				if(characterLimitError.length){
					var error = characterLimitError[0];
					pubjs.alert(LANG('重定向选择的%1%2数量超过最大限制数量,最大限制数量为50个', characterMap[error['type']], characterMap[error['name']]));
					return false;
				}
			}

			return true;
		}
	});
	exports.app_Character = APP_Character;

	// 网络类型
	var APP_Network = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('网络类型：') + '</label>',
					'<div class="group-content" pub-name="checkbox" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				checkbox: {
					'reqType': 'websocket',
					'url': 'category/network',
					'id': 'BdxId',
					'name': 'Name',
					'width': 100
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.checkbox.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('checkbox')){
				this.$.relation.setValue(data.Relation);
				this.$.checkbox.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var desc = this.$.checkbox.getDesc();
			var data = this.$.checkbox.getValue();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('、') + ']'
			};
			return result;
		}
		,validate: function(){
			var data = this.getValue();
			if(data.Data && !data.Data.length){
				pubjs.alert(LANG('至少需选择一个网络类型'));
				return false;
			}
			return true;
		}
	});
	exports.app_Network = APP_Network;

	// 设备
	var APP_DeviceType = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignOrientDeciveAppDecive',
			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 600);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('设备类型：') + '</label>',
					'<div class="group-content" pub-name="deviceType" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('设备品牌：') + '</label>',
					'<div class="group-content" pub-name="deviceBrand" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('设备型号：') + '</label>',
					'<div class="group-content" pub-name="deviceModel" pub-mod="campaign/modules/deviceType.base"/>',
				'</div>',

			].join('')).appendTo(el);

			self.buildFromTemplate({
				deviceType: {
					'reqType': 'websocket',
					'url': 'category/deviceType',
					'id': 'BdxId',
					'name': 'Name',
					'width': 100
				},
				deviceBrand: {
					'reqType': 'websocket',
					'url': 'category/deviceBrand',
					'id': 'BdxId',
					'name': 'Name',
					'width': 100
				},
				deviceModel: {
					'reqType': 'websocket',
					'url': 'category/deviceModel',
					'id': 'BdxId',
					'name': 'Name',
					'Type': 'deviceModel'
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			if(this.get('deviceModel')){
				this.$.deviceModel.reset();
			}
			if(this.get('deviceType')){
				this.$.deviceType.reset();
			}
			if(this.get('deviceBrand')){
				this.$.deviceBrand.reset();
			}
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			var value = {};
			var Data = data.Data;
			this.$data = data;

			if(data){
				if(this.get('relation')){
					this.$.relation.setValue(data.Relation);
				}
				if(this.get('deviceModel')){
					this.$.deviceModel.setData(Data.DeviceModel);
				}
				if(this.get('deviceType')){
					this.$.deviceType.setValue(Data.DeviceType);
				}
				if(this.get('deviceBrand')){
					this.$.deviceBrand.setValue(Data.DeviceBrand);
				}
			}

			return this;
		}
		,getValue: function() {
			var deviceType = this.$.deviceType.getValue();
			var deviceBrand = this.$.deviceBrand.getValue();
			var deviceModel = this.$.deviceModel.getData();

			var deviceType_desc = this.$.deviceType.getDesc();
			var deviceBrand_desc = this.$.deviceBrand.getDesc();
			var deviceModel_desc = this.$.deviceModel.getDesc(deviceModel.deviceModel);

			var desc = [];

			if(deviceType_desc.length){
				desc.push(deviceType_desc.join('、'));
			}
			if(deviceBrand_desc.length){
				desc.push(deviceBrand_desc.join('、'));
			}
			if(deviceModel_desc.length){
				desc.push(deviceModel_desc.join('、'));
			}

			var tmp = {
				'DeviceType': deviceType || null,
				'DeviceBrand': deviceBrand || null,
				'DeviceModel': deviceModel.deviceModel || null
			}

			var result = {
				'Data': tmp,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('；')+ ']'
			};
			return result;
		}
		,validate: function(data){
			if(data){
				if(!data.Data.DeviceType.length && !data.Data.DeviceBrand.length && !data.Data.DeviceModel.length){
					pubjs.alert(LANG('请至少需选择一个筛选条件'));
					return false;
				}
			}
			return true;
		}
	});
	exports.app_DeviceType = APP_DeviceType;

	// 操作系统
	var APP_OSType = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('操作系统：') + '</label>',
					'<div class="group-content" pub-name="os" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('设备ID类型：') + '</label>',
					'<div class="group-content" pub-name="deviceIdType" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('系统语言：') + '</label>',
					'<div class="group-content" pub-name="language" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('浏览器：') + '</label>',
					'<div class="group-content" pub-name="browser" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>'

			].join('')).appendTo(el);

			self.buildFromTemplate({
				'os': {
					'reqType': 'websocket',
					'url': 'category/osMt',
					'id': 'BdxId',
					'name': 'Name'
				},
				'deviceIdType': {
					'reqType': 'websocket',
					'url': 'category/deviceIdType',
					'id': 'BdxId',
					'name': 'Name',
				},
				'language': {
					'reqType': 'websocket',
					'url': 'category/systemLang',
					'id': 'BdxId',
					'name': 'Name',
				},
				'browser': {
					'reqType': 'websocket',
					'url': 'category/browserMt',
					'id': 'BdxId',
					'name': 'Name',
					// 'width': 100,
				},
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			if(this.get('os')){
				this.$.os.reset();
			}
			if(this.get('browser')){
				this.$.browser.reset();
			}
			if(this.get('language')){
				this.$.language.reset();
			}
			if(this.get('deviceIdType')){
				this.$.deviceIdType.reset();
			}
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			var value = {};
			var Data = data.Data;
			this.$data = data;

			if(data){
				if(this.get('relation')){
					this.$.relation.setValue(data.Relation);
				}
				if(this.get('os')){
					this.$.os.setValue(Data.OSType);
				}
				if(this.get('browser')){
					this.$.browser.setValue(Data.BrowserType);
				}
				if(this.get('language')){
					this.$.language.setValue(Data.Language);
				}
				if(this.get('deviceIdType')){
					this.$.deviceIdType.setValue(Data.DeviceIdType);
				}
			}

			return this;
		}
		,getValue: function() {
			var os = this.$.os.getValue();
			var browser = this.$.browser.getValue();
			var language = this.$.language.getValue();
			var deviceIdType = this.$.deviceIdType.getValue();

			var os_desc = this.$.os.getDesc();
			var browser_desc = this.$.browser.getDesc();
			var language_desc = this.$.language.getDesc();
			var deviceIdType_desc = this.$.deviceIdType.getDesc();

			var desc = [];

			if(os_desc.length){
				desc.push(os_desc.join('、'));
			}
			if(deviceIdType_desc.length){
				desc.push(deviceIdType_desc.join('、'));
			}
			if(language_desc.length){
				desc.push(language_desc.join('、'));
			}
			if(browser_desc.length){
				desc.push(browser_desc.join('、'));
			}

			var tmp = {
				'OSType': os || null,
				'BrowserType': browser || null,
				'Language': language || null,
				'DeviceIdType': deviceIdType || null
			}

			var result = {
				'Data': tmp,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('；')+ ']'
			};
			return result;
		}
		,validate: function(data){
			if(data){
				if(!data.Data.OSType.length && !data.Data.BrowserType.length && !data.Data.Language.length && !data.Data.DeviceIdType.length){
					pubjs.alert(LANG('请至少需选择一个筛选条件'));
					return false;
				}
			}
			return true;
		}
	});
	exports.app_OSType = APP_OSType;

	// LBS定向
	var APP_LBS = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 600);

			$([
				'<div class="mt10" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div>' + LANG('LBS定向：') + '</div>',
				'<div class="mt10" pub-name="lbs" pub-mod="campaign/modules/lbs.base"/>'
			].join('')).appendTo(el);

			self.buildFromTemplate({
				lbs: {
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.lbs.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('lbs')){
				this.$.relation.setValue(data.Relation);
				this.$.lbs.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var desc = [];
			var data = this.$.lbs.getValue();

			util.each(data, function(item){
				if(item){
					desc.push([
						LANG('对坐标点"%1,%2"在%3米为半径的范围内的设备进行定向', item.Lng, item.Lat, item.Radius)
					].join(''));
				}
			});

			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('、') + ']'
			};
			return result;
		}
	});
	exports.app_LBS = APP_LBS;

	// 网络运营商
	var APP_Carriers = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {

			});
			this.$data = null;
			this.Super('init', arguments);
		}
		,afterBuild: function() {
			var self = this;
			var el = self.getDOM();
			el.css('min-height', 400);

			$([
				'<div class="mt10 dn" pub-name="relation" pub-mod="promotion/popwin/settings.relation"/>',
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('网络运营商：') + '</label>',
					'<div class="group-content" pub-name="checkbox" pub-mod="modules/checkBoxGroup.base"/>',
				'</div>',
			].join('')).appendTo(el);

			self.buildFromTemplate({
				checkbox: {
					'reqType': 'websocket',
					'url': 'category/appCarrier',
					'id': 'BdxId',
					'name': 'Name'
				}
			});
		}
		,afterBuildTemplate: function(){
			if(this.$data){
				this.setValue(this.$data);
			}
		}
		,reset: function() {
			this.$.relation.reset();
			this.$.checkbox.reset();
			this.$data = null;
			return this;
		}
		,setValue: function(data) {
			this.$data = data;
			if(data && this.get('relation') && this.get('checkbox')){
				this.$.relation.setValue(data.Relation);
				this.$.checkbox.setValue(data.Data);
			}
			return this;
		}
		,getValue: function() {
			var desc = this.$.checkbox.getDesc();
			var data = this.$.checkbox.getValue();
			var result = {
				'Data': data,
				'Relation': this.$.relation.getValue(),
				'Desc': '[' +desc.join('、') + ']'
			};
			return result;
		}
		,validate: function(){
			var data = this.getValue();
			if(data.Data && !data.Data.length){
				pubjs.alert(LANG('至少需选择一个网络运营商'));
				return false;
			}
			return true;
		}
	});
	exports.app_Carriers = APP_Carriers;


	// 活动列表 —— 批量操作的部分编辑内容
	var Main = popwin.extend({
		init:function(config) {
			config = pubjs.conf(config, {
				'class': 'P-campaignBatchEdit P-campaignOrientPopwin',
				'title': LANG('批量编辑'),
				'param': null,
				'silence': true,
				// 'width': 960,
				'size': 'm',
				'style': {'bodyClass': 'pr uk-form'},
				'types': {
					/**
					 * 配置说明
					 * [type]: {
					 *    url: '',          该类型的请求url
					 *    module: '',       该类型对应的模块，可为模块类，也可为uri
					 *    config: '',       模块对应配置
					 *    getter: 'getData' 获取数据方法，默认会调用模块的getValue，当为String时调用对应的方法，当为function时, function的this指向当前模块, 第一个参数为类型子模块实例
					 * }
					 */
					// 通用条件-------------
					// 交易类型
					BidType: {
						module: BidType
					},
					// RTB广告位
					RTBSpot: {
						module: RTBSpot
					},
					// 订单广告位
					DealSpot: {
						// width: 1000,
						module: DealSpot2
					},
					// 交易订单
					Deals: {
						width: 1000,
						module: Deals
					},
					// 媒体广告位
					MediaSpot: {
						width: 1000,
						module: MediaSpot
					},
					// 投放日期
					Time: {
						module: Time
					},
					// 日程设置
					TimeSet: {
						width: 1000,
						module: TimeSet
					},
					// 投放地区
					Zone: {
						width: 1100,
						module: Zone
					},
					// 自由人群
					NPeople: {
						module: NPeople
					},
					// IP地址
					IpSections: {
						module: IpSections
					},
					// 上网场景
					Scene: {
						module: Scene
					},
					// 百度指数
					HotWord: {
						module: HotWord
					},
					// 百度tag_id
					CustomizedUserTag: {
						module: CustomizedUserTag
					},
					// 视频定向
					VideoDirect: {
						width: 1200,
						module: VideoDirect
					},
					// 屏次
					Screen: {
						module: Screen
					},
					// 展现形式
					ViewType: {
						module: ViewType
					},
					// 渠道
					Adx: {
						module: Channel
					},
					// web条件-------------
					// 三方人群
					TBPeople: {
						width: 1200,
						module: TBPeople,
					},
					// 秒针人群
					MZPeople: {
						width: 1200,
						module: MZPeople
					},
					// 其他人群
					BdxPeople: {
						width: 1200,
						module: BDXPeople
					},
					// 重定向
					Character: {
						width: 1200,
						module: Character
					},
					// 客户端
					Client: {
						width: 1000,
						module: Client
					},
					// 温度设置
					Temperature: {
						module: Temperature
					},
					// 湿度设置
					HumidityLevels: {
						module: HumidityLevels
					},
					// 空气指数
					ApiLevels: {
						module: ApiLevels
					},
					// 温差设置
					TemperatureDiff: {
						module: TemperatureDiff
					},
					// 页面关键词
					PageKeyword: {
						width: 1000,
						module: PageKeyword
					},
					// 用户关键词
					UserKeyword: {
						width: 1000,
						module: UserKeyword
					},

					// app条件-------------
					// 其他人群
					APP_BdxPeople: {
						width: 1200,
						module: APP_BdxPeople
					},
					// 重定向
					APP_Character: {
						width: 1200,
						module: APP_Character,
					},
					// 网络类型
					APP_Network: {
						module: APP_Network,
					},
					// 设备
					APP_DeviceType: {
						width: 1000,
						module: APP_DeviceType,
					},
					// 操作系统
					APP_OSType: {
						module: APP_OSType
					},
					// LBS定向
					APP_LBS: {
						module: APP_LBS
					},
					APP_Carriers: {
						module: APP_Carriers
					}
				}
			});

			this.$param = {};
			this.$childPrefix = 'TYPE_CHILD_';
			this.$types = config.get('types');
			this.$isEdit = false;
			this.Super('init', arguments);
		},
		afterBuild:function() {
			this.Super('afterBuild', arguments);
			this.buildFromTemplate();
			var con = this.getContainer();
			con.css('background', '#fff');
		},
		reset: function() {
			var self = this;
			var cs = self.$;
			self.Super('reset', arguments);
			self.hideLoading();
			self.$currentType = null;
			// 重置子模块
			util.each(self.$types, function(opts, type) {
				var name = self.$childPrefix + type;
				if (cs[name]) {
					cs[name].reset().hide();
				}
			});
			return self;
		},
		// 设置活动类型
		setChannelType: function(channel){
			// 活动类型，区分pc，移动，监测
			this.$channelType = channel || 0;
			return this;
		},
		// 设置类型
		setType: function(type) {
			var self = this;
			var types = self.$types;

			if(types[type].width){
				self.setWidth(types[type].width);
			}else{
				self.setWidth(850);
			}

			var pre = self.$childPrefix;
			var name = pre + type;
			var opts = types[type || ''] || {};
			var config = util.extend(opts.config, {target: this.getContainer(),channelType: self.$channelType});
			var afterCreate = function(mod) {
				self.hideLoading();
				opts.loading = false;
				self.update();
				mod.show();

				// 模块创建中，上层调用了setData的值，在模块创建完后，这值对应的值
				if (opts.afterCreateData && mod.setValue)
				{
					mod.setValue(opts.afterCreateData);
				}
			}

			if (opts) {
				self.$currentType = type;

				// 如果模块不存在
				if (!self.$[name]) {
					// 模块还没创建完毕，loading盖住
					if (opts.loading) {
						self.showLoading();
					// 异步创建模块，创建过程上锁，并用loading盖住
					} else if (util.isString(opts.module)) {
						opts.loading = true;
						self.showLoading();
						self.createAsync(name, opts.module, config, afterCreate);
					// 同步创建模块
					} else if (util.isClass(opts.module)){
						opts.loading = true;
						self.showLoading();
						afterCreate(self.create(name, opts.module, config));
					} else {
						pubjs.error("类型为:" + type + "的module属性配置错误");
					}
				} else {
					self.$[name].show(self.$channelType);
					self.update();
				}
			} else {
				pubjs.error("配置中找不到该类型:" + type);
			}

			return this;
		},
		setParam: function(ids) {
			this.$param = {
				ids: ids
			};
			return this;
		},
		setData: function(data) {
			if (data)
			{
				var self = this;
				var types = self.$types;
				var type = self.$currentType;
				var pre = self.$childPrefix;
				var name = pre + type;

				var opts = types[type];
				if (opts)
				{
					if (opts.loading)
					{
						opts.afterCreateData = data;
					}
					else if(self.$[name] && self.$[name].setValue)
					{
						self.$[name].setValue(data);
					}
				}
			}
			return this;
		},
		setAnchor: function(anchor){
			this.$anchor = anchor;
			return this;
		},
		setEdit: function(boolen){
			// 是否编辑状态
			this.$isEdit = !!boolen;
			return this;
		},
		getTitle: function(){
			var self = this;
			var dom = self.$doms.title;
			return dom.text() || '';
		},
		onOk: function() {
			var data;
			var self = this;
			var type = self.$currentType;
			var opts = self.$types[type];
			var name = self.$childPrefix + type;
			var mod = self.get(name);
			var getter = opts.getter;

			if (!getter) {
				data = mod.getValue();
			} else if (util.isString(getter)) {
				data = mod[getter]();
			} else if (util.isFunction(getter)) {
				data = getter.apply(self, mod, opts);
			}

			if(mod.validate){
				if(!mod.validate(data)){
					return false;
				}
			}

			data.Type = type;
			data.anchor = self.$anchor;
			data.Title = self.getTitle();
			data.IsEdit = self.$isEdit;


			self.fire('settingsSuccess', data);

			self.hide();
			// 还原编辑状态
			self.$isEdit = false;
			return false;
		},
		// --------------------------------------------
		// 接收一些远程广播，因为子模块还没有构建好，所以暂时在父这里接收先
		onCampaignSelectOrderSuccess: function(ev){
			this.$selectDeal = ev.param;
		},
		onCampaignBidTypeChange: function(ev){
			this.$bidType = ev.param;
		}
	});
	exports.main = Main;


	/**
	*	重定向结果构造成字符串
	*	@param {Object}	redirectData	对应的数据
	*	@param {String} name 			对应的object的名字
	*/
	function redirectString (redirectData, name){
		var result = [];

		for (var redirectValue in redirectData) {
			var data = redirectData[redirectValue];
			var namePrefix = (redirectValue === 'Exclude' ? LANG('排除') : LANG('包含'));
			var nameContent = '';
			switch (name){
				case 'Device':
					nameContent = LANG('设备人群：');
					break;
				case 'Cookie':
					nameContent = LANG('cookies人群：');
					break;
				case 'Ip':
					nameContent = LANG('Ip人群：');
					break;
			}

			if (data.length) {
				var list = [];
				var relation = data[0].PrevLogical === 'or' ? LANG(' 或 ') : LANG(' 且 ');
				data.forEach(function(item){
					list.push(item.text);
				});
				var string = namePrefix + nameContent + '[' + list.join(relation) + ']';
				result.push(string);
			}

		}

		return result;
	}
});